package com.hspedu.collection_;

import java.util.ArrayList;
import java.util.List;

/**
 * Collection集合的常用方法
 * @author enomix
 * @date 2022-06-14 19:44
 */
public class CollectionMethod {
    public static void main(String[] args) {
        List list = new ArrayList();
        //add: 添加单个元素
        list.add("jack");
        list.add(10);
        list.add(true);
        System.out.println("list = " + list);

        //remove：删除某个元素
        list.remove(true);
        System.out.println("list = " + list);

        //contains: 是否包含
        System.out.println("jack是否存在：" + list.contains("jack"));

        //size: 获取元素个数
        System.out.println(list.size());

        //isEmpty: 是否为空
        System.out.println(list.isEmpty());

        //clear: 清空
        list.clear();
        System.out.println("list = " + list);

        ArrayList arrayList = new ArrayList();
        arrayList.add("红楼梦");
        arrayList.add("三国演义");

        //addAll: 添加多个元素
        list.addAll(arrayList);
        System.out.println("list = " + list);

        //containsAll: 查找多个元素是否都存在
        System.out.println(list.containsAll(arrayList));

        //removeAll: 删除多个元素
        list.removeAll(arrayList);
        System.out.println("list = " + list);
    }
}
